//
//  CTTEListVC.m
//  digitalCurrency
//
//  Created by 小震GG on 2019/7/8.
//  Copyright © 2019 XinHuoKeJi. All rights reserved.
//

#import "CTTEListVC.h"
#import "CTQGCell.h"
#import "CTQGListModel.h"
#import "HomeNetManager.h"

@interface CTTEListVC ()
@property (nonatomic, strong) NSMutableArray *qglists;
@property (nonatomic, assign) NSInteger page;
@property (nonatomic, strong) LYEmptyView *emptyView;

@property (nonatomic, strong) UIView *headView;
@property (nonatomic, strong) UILabel *shouYiLB;
@property (nonatomic, strong) UILabel *shenDuLB;
@property (nonatomic, strong) UILabel *kuanDuLB;
@property (nonatomic, strong) UILabel *pengDuiLB;

@end

@implementation CTTEListVC
- (instancetype)init
{
    self = [super init];
    if (self) {
        _qglists = [NSMutableArray array];
        _page = 1;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.viewTitle.text = LocalizationKey(@"分红收益");
    
    [self.view addSubview:self.tableView];
    self.tableView.rowHeight = 62;
    self.tableView.separatorColor = [UIColor clearColor];
    [self.tableView registerClass:[CTQGCell class] forCellReuseIdentifier:@"qgcell"];
    
    [self headRefreshWithScrollerView:self.tableView];
    [self footRefreshWithScrollerView:self.tableView];
    
    [self getRushRecordList];
    [self setHeadView];
}

- (void)setHeadView{
    
    self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWindowW,  130)];
    self.tableView.tableHeaderView = self.headView;
    self.tableView.tableFooterView = [UIView new];
    
    UIView *bgView = [[UIView alloc]init];
    [self.headView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.top.equalTo(13);
        make.right.equalTo(-20);
        make.height.equalTo(120);
    }];
    bgView.backgroundColor = tMainColor;
    bgView.layer.cornerRadius = 5.0;
    
    UILabel *zongZiChanLB = [[UILabel alloc]init];
    [bgView addSubview:zongZiChanLB];
    [zongZiChanLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.top.equalTo(16);
    }];
    zongZiChanLB.textColor = [UIColor whiteColor];
    zongZiChanLB.font = kFont(14);
    zongZiChanLB.text = LocalizationKey(@"总收益(USDT)");
    
    self.shouYiLB = [[UILabel alloc]init];
    [bgView addSubview:self.shouYiLB];
    [self.shouYiLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(zongZiChanLB.mas_right).offset(18);
        make.centerY.equalTo(zongZiChanLB);
    }];
    self.shouYiLB.textColor = [UIColor whiteColor];
    self.shouYiLB.font = kFont(12);
    self.shouYiLB.text = @"00.00";
    
    UILabel *shenTitleLB = [[UILabel alloc]init];
    [bgView addSubview:shenTitleLB];
    [shenTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.top.equalTo(zongZiChanLB.mas_bottom).offset(8);
    }];
    shenTitleLB.textColor = [UIColor whiteColor];
    shenTitleLB.font = kFont(14);
    shenTitleLB.text = LocalizationKey(@"深度总业绩");
    
    self.shenDuLB = [[UILabel alloc]init];
    [bgView addSubview:self.shenDuLB];
    [self.shenDuLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(shenTitleLB.mas_right).offset(18);
        make.centerY.equalTo(shenTitleLB);
    }];
    self.shenDuLB.textColor = [UIColor whiteColor];
    self.shenDuLB.font = kFont(12);
    self.shenDuLB.text = @"00.00";

    UILabel *kuanTitleLB = [[UILabel alloc]init];
    [bgView addSubview:kuanTitleLB];
    [kuanTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.top.equalTo(shenTitleLB.mas_bottom).offset(8);
    }];
    kuanTitleLB.textColor = [UIColor whiteColor];
    kuanTitleLB.font = kFont(14);
    kuanTitleLB.text = LocalizationKey(@"宽度总业绩");
    
    self.kuanDuLB = [[UILabel alloc]init];
    [bgView addSubview:self.kuanDuLB];
    [self.kuanDuLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(kuanTitleLB.mas_right).offset(18);
        make.centerY.equalTo(kuanTitleLB);
    }];
    self.kuanDuLB.textColor = [UIColor whiteColor];
    self.kuanDuLB.font = kFont(12);
    self.kuanDuLB.text = @"00.00";
    
    UILabel *pengTitleLB = [[UILabel alloc]init];
    [bgView addSubview:pengTitleLB];
    [pengTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.top.equalTo(kuanTitleLB.mas_bottom).offset(8);
    }];
    pengTitleLB.textColor = [UIColor whiteColor];
    pengTitleLB.font = kFont(14);
    pengTitleLB.text = LocalizationKey(@"当前碰对情况");
    
    self.pengDuiLB = [[UILabel alloc]init];
    [bgView addSubview:self.pengDuiLB];
    [self.pengDuiLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pengTitleLB.mas_right).offset(18);
        make.centerY.equalTo(pengTitleLB);
    }];
    self.pengDuiLB.textColor = [UIColor whiteColor];
    self.pengDuiLB.font = kFont(12);
    self.pengDuiLB.text = @"0";
    
    UIImageView *rightImage = [[UIImageView alloc]init];
    [bgView addSubview:rightImage];
    [rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(-20);
        make.top.equalTo(13);
    }];
    rightImage.image = ImageName(@"finance_left");
}

#pragma mark-下拉刷新数据
- (void)refreshHeaderAction {
    _page = 1;
    [self getRushRecordList];
}

- (void)refreshFooterAction {
    _page++;
    [self getRushRecordList];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _qglists.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CTQGCell *cell = [CTQGCell createTableView:tableView];
    NSDictionary *dataDic = _qglists[indexPath.row];
//    cell.createTime.text = [ToolUtil timeIntervalToTimeString:model.time WithDateFormat:@"YY-MM-dd HH:mm:ss"];
//    cell.coinNumber.text = [NSString stringWithFormat:@"%@", [ToolUtil judgeStringForDecimalPlaces:[NSString stringWithFormat:@"%@",model.amount] point:4]];
    
    cell.bgView.frame = CGRectMake(0, 0, kWindowW, 62);
    cell.bgView.layer.cornerRadius = 0.01;
    cell.bgView.layer.shadowColor = [UIColor whiteColor].CGColor;
    cell.coinName.hidden = YES;
    
    [cell.coinName mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.centerX.mas_equalTo(30);
    }];
    [cell.coinNumber mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-20);
    }];
    [cell.createTime mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
    }];
    
   cell.createTime.text = [NSString stringWithFormat:@"%@",dataDic[@"createTime"]];
    cell.coinNumber.text = [NSString stringWithFormat:@"+%@ USDT",[NSString stringWithFormat:@"%@", [ToolUtil judgeStringForDecimalPlaces:[NSString stringWithFormat:@"%@",dataDic[@"value"]] point:4]]];
    
    if (indexPath.row%2!=0) {
        cell.bgView.backgroundColor = [[UIColor colorWithHEX:mainBlackColor] colorWithAlphaComponent:0.5];
    }
    else {
        cell.bgView.backgroundColor = [UIColor whiteColor];
    }
    
    return cell;
}

- (void)getRushRecordList {
    [HomeNetManager getTransformationEarningsList:[YLUserInfo shareUserInfo].ID page:@(_page) row:@(20) CompleteHandle:^(id resPonseObj, int code) {

        if (code) {
            NSInteger codeInt = [resPonseObj[@"code"] integerValue];
            if (codeInt == 0) {
                NSArray *data = resPonseObj[@"data"][@"list"];
                
                self.pengDuiLB.text = [NSString stringWithFormat:@"%@",resPonseObj[@"data"][@"touchNum"]];
                self.kuanDuLB.text = [NSString stringWithFormat:@"%@",resPonseObj[@"data"][@"widthAmount"]];
                self.shenDuLB.text = [NSString stringWithFormat:@"%@",resPonseObj[@"data"][@"depthAmount"]];
                self.shouYiLB.text = [NSString stringWithFormat:@"%@",resPonseObj[@"data"][@"totalIncome"]];

                if (_page == 1) {
                    [self.qglists removeAllObjects];
                }
                else {
                    if (data.count == 0) {
                        self.tableView.mj_footer.state = MJRefreshStateNoMoreData;
                    }
                }

                for (NSDictionary *sub in data) {
                    [self.qglists addObject:sub];
                }
                self.tableView.ly_emptyView = self.emptyView;
                [self.tableView reloadData];
            }
            else {
                [self.view makeToast:resPonseObj[MESSAGE] duration:1.5 position:CSToastPositionCenter];
            }
        }
        else {
            [self.view makeToast:LocalizationKey(@"noNetworkStatus") duration:1.5 position:CSToastPositionCenter];
        }
    }];
    
}
- (LYEmptyView *)emptyView {
    if (!_emptyView) {
        _emptyView = [LYEmptyView emptyViewWithImageStr:@"emptyData" titleStr:[[ChangeLanguage bundle] localizedStringForKey:@"NoData" value:nil table:@"English"]];
        _emptyView.titleLabTextColor = tThreeColor;
        _emptyView.titleLabFont = [UIFont systemFontOfSize:19];
        _emptyView.contentViewY = SCREEN_HEIGHT/2.0-100;
    }
    return _emptyView;
}
@end
